﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.Procurements;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Write.API.Applicantions.Command.ProcurementsCommand;

namespace T.E.ERP.Write.API.Applicantions.CommandHandler.ProcurementsCommandCommand
{
    /// <summary>
    /// 采购到货修改
    /// </summary>
    public class UpdatePurchaseArrivalCommandHander : IRequestHandler<UpdatePurchaseArrivalCommand, APIResult<object>>
    {


        private readonly IBaseRepository<PurchaseArrival> repository;


        private readonly IMapper mapper;

        public UpdatePurchaseArrivalCommandHander(IBaseRepository<PurchaseArrival> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }
        /// <summary>
        /// 处理
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<object>> Handle(UpdatePurchaseArrivalCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result =new APIResult<object>();

            result.Code = APIEnum.修改成功;
            result.Msg = APIEnum.修改成功.ToString();

            var list = repository.GetAll().Result.Where(x => x.PurchaseArrivaId == request.PurchaseArrivaId).FirstOrDefault();
            list.PurchaseArrivaId =request.PurchaseArrivaId;
            list.DocumentCode =request.DocumentCode;
            list.DocumentStatus = request.DocumentStatus;
            list.BusinessStatus = request.BusinessStatus;
            list.Documentid = request.Documentid;
            list.BusinessName = request.BusinessName;
            list.PurchasingDe = request.PurchasingDe;
            list.PurchasingTiem = request.PurchasingTiem;
            list.PurchaseOrder = request.PurchaseOrder;
            list.Supplier =request.Supplier;
            list.Warehouse =request.Warehouse;
            list.ProgressStatus =request.ProgressStatus;
            list.RemarksInformation =request.RemarksInformation;
            list.BocumentStatus =request.BocumentStatus;

            await repository.Update(list);
            return await Task.FromResult(result);
        }
    }
}
